var dataValidated = false;
function CloseWindowAndRefreshParent()
{
	window.opener.location.reload();
	window.close();
}

//Version page - No frame
//If Electronic File is checked, then Hardcopy is unselected and the file browser control is enabled. 
//If electronic file is unchecked, then file browser control is disabled.
function ToggleControlsForVersionsElectronicFile(attachmentElectronic, attachmentHardCopy, attachedFile, newTitle)
{ 
	if (document.getElementById(attachmentElectronic).checked)
	{
		document.getElementById(attachmentHardCopy).checked = false;
		document.getElementById(attachedFile).disabled = false;
		document.getElementById(newTitle).disabled = false;		
	}
	else
	{
	    document.getElementById(attachedFile).disabled = true;
	    document.getElementById(newTitle).disabled = true;
	}
}

//Version page - No frame
//If Hardcopy is checked, then electronic file is unchecked and the file browser control is disabled.
function ToggleControlsForVersionsHardCopy(attachmentHardCopy, attachmentElectronic, attachedFile, newTitle)
{
	if (document.getElementById(attachmentHardCopy).checked)
	{
		document.getElementById(attachmentElectronic).checked = false;
		document.getElementById(attachedFile).disabled = true;
		document.getElementById(newTitle).disabled = true;
	}
}



function Validate()
{
	if (document.getElementById('attachmentHardCopy').checked)
		return true;
	if (document.getElementById('attachmentElectronic').checked)
	{
		if (document.getElementById('attachedFile').value != '')
		{
			return true;
		}
		else
			alert('Select a file to upload');
	}
	else
		alert('Select the mode of attachment');
	
	return false;
}

function RestrictFileSelection(fileToDiff, showDifferences)
{
	var rowsSelected = document.getElementById('selectedRowsForDifferences');
	var arraySelectFiles = rowsSelected.value.split("^"); //when two check boxes are selected this line would result in 3 strings (the 3rd is an empty string)
	
	if (document.getElementById(fileToDiff).getAttribute('checked')) //if checked
	{
		if (arraySelectFiles.length == 3) //two files are already selected
		{
			//retrieve the first control and unselect it
			document.getElementById(arraySelectFiles[0]).setAttribute('checked', false); //deselect the oldest
			rowsSelected.value = rowsSelected.value.replace(arraySelectFiles[0] + "^", ""); //remove it from the hidden control
		}
		rowsSelected.value = rowsSelected.value + fileToDiff + '^'; //add the now selected file to the hidden control
		
		if (arraySelectFiles.length >= 2) //enable the Show Differences button if 1 file is already selected (the current file selection makes the total count to 2)
			document.getElementById(showDifferences).setAttribute('disabled', false);
	}
	else //if unchecked
	{
		rowsSelected.value = rowsSelected.value.replace(fileToDiff + "^", ""); //remove from the hidden control
		document.getElementById(showDifferences).setAttribute('disabled', true); //at any point in time as only 2 files are selected, deselecting one of them should disable the Show Differences button
	}
}

